package com.booking.controller;

import com.booking.common.dto.ClientResp;
import com.booking.controller.model.req.user.LoginReq;
import com.booking.controller.model.req.user.UserCertificationReq;
import com.booking.controller.model.req.user.UserCreateReq;
import com.booking.controller.model.req.user.UserUpdateReq;
import com.booking.controller.model.res.UserDetail;
import com.booking.dao.entity.UserInfo;
import com.booking.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author Qikai.Lin
 * @date 2023/4/23
 */
@Slf4j
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserService userService;
    //创建用户
    @PostMapping("/create")
    public ClientResp<UserInfo> create(@RequestBody @Valid UserCreateReq request) {
        return ClientResp.success(userService.create(request));
    }
    //更新用户
    @PostMapping("/update")
    public ClientResp<String> update(@RequestBody @Valid UserUpdateReq request) {
        userService.updateById(request);
        return ClientResp.success();
    }
    //查询用户详情
    @PostMapping("/get")
    public ClientResp<UserDetail> get(@RequestParam Long userId) {
        return ClientResp.success(userService.getDetail(userId));
    }
    //删除用户
    @PostMapping("/delete")
    public ClientResp<String> delete(@RequestParam Long userId) {
        userService.delete(userId);
        return ClientResp.success();
    }
    //登陆
    @PostMapping("/login")
    public ClientResp<UserInfo> login(@RequestBody @Valid LoginReq request) {
        return ClientResp.success(userService.login(request));
    }
    //实名认证
    @PostMapping("/certification")
    public ClientResp<String> certification(@RequestBody @Valid UserCertificationReq request) {
        userService.certification(request);
        return ClientResp.success();
    }
    //用户点赞
    @PostMapping("/like")
    public ClientResp<String> like(@RequestParam Long commentId) {
        return ClientResp.success();
    }
}
